<template>
    <div class="link-section p-t-55">
        <div class="card-box">
            <a
                :href="item.url"
                class="card-item"
                v-for="item in list"
                :key="item.id"
                target="_blank"
            >
                <div class="inner">
                    <div class="card-img">
                        <img :src="item.image_url" />
                    </div>
                    <p class="card-text">
                        <span>{{ item.title }}</span>
                        <span>{{ item.desc }}</span>
                    </p>
                </div>
            </a>
        </div>
        <div class="format-box">
            <div class="format-content" v-html="format.info"></div>
        </div>
        <layout-footer />
    </div>
</template>

<script>
import { getCurrentInstance, ref, toRefs, reactive } from 'vue';
import linkService from '@/global/service/linkService.js';

export default {
    name: 'Link',
    setup() {
        const { proxy } = getCurrentInstance();
        let format = ref('');
        let list = ref([]);

        // 获取友联列表
        const getList = async () => {
            const { code, data } = await linkService.getList();
            if (code === 200) {
                list.value = data.list;
            }
        };
        // 获取友链信息
        const getInfo = async () => {
            const { code, data } = await linkService.getInfo();

            if (code === 200) {
                format.value = data.list;
            }
        };
        getInfo();
        getList();

        return {
            format,
            list
        };
    }
};
</script>

<style lang="less">
p {
    margin: 0 !important;
}
.link-section {
    padding-left: 1rem;
    padding-right: 1rem;

    .format-box {
        background-color: rgba(255, 255, 255, 0.9);
        box-shadow: 0 8px 16px 0 rgb(0 0 0 / 16%), 0 2px 10px 0 rgb(0 0 0 / 12%);
        border-radius: 5px;
        max-width: 1100px;
        margin: 20px auto;

        .format-content {
            padding: 20px;
        }
    }

    .card-box {
        max-width: 1100px;
        margin: 0 auto;
        padding: 20px 0;
        display: grid;
        grid-template-columns: repeat(4, 1fr);
        grid-gap: 20px;
        grid-auto-flow: row;

        @media (max-width: 800px) {
            grid-template-columns: repeat(1, 1fr);
        }
    }

    .card-item {
        background-color: rgba(255, 255, 255, 1);
        box-shadow: 0 8px 16px 0 rgb(0 0 0 / 16%), 0 2px 10px 0 rgb(0 0 0 / 12%);
        border-radius: 5px;
        padding: 10px 30px;
        position: relative;
        overflow: hidden;

        &::before {
            content: '';
            background: linear-gradient(90deg, #36a8f1, #f488a7);
            transform: skew(45deg, 0);
            width: 0;
            height: 100%;
            position: absolute;
            top: 0;
            left: -60px;
            // z-index: 1;
            transition: all 0.5s;
            opacity: 0.5;
        }
        &:hover::before {
            width: 180%;
        }
        .inner {
            display: flex;
        }
        .card-img {
            display: flex;

            img {
                width: 65px;
                height: 65px;
                border-radius: 50%;
                box-shadow: 0 8px 16px 0 rgb(0 0 0 / 16%), 0 2px 10px 0 rgb(0 0 0 / 12%);
            }
        }
        .card-text {
            span {
                display: block;
                width: 125px;
                overflow: hidden;
                text-overflow: ellipsis;
                -o-text-overflow: ellipsis;
                white-space: nowrap;
                padding: 7px 0 7px 15px;
                font-size: 15px;

                &:first-child {
                    color: #2edfa3;
                }
                &:nth-child(2) {
                    color: #606f7b;
                    border-top: 1px dashed #ddd;
                }
            }
        }
    }
}
</style>
